//
//  KDSubscribCell.m
//  WangJingApp
//
//  Created by 魏强 on 17/1/6.
//  Copyright © 2017年 KDTech. All rights reserved.
//

#import "KDSubscribCell.h"
#import "SVProgressHUD.h"
#import "KDSubscribCellModel.h"
#import "KDHomeRequestTool.h"
#import "KDHomeListPageCollectParam.h"
#import "KDHomeListPageCollectResult.h"
#import "KDHomeListPageUnCollectResult.h"
#import "KDHomeListPageUnCollectParam.h"
#import "NSString+KD.h"
@interface KDSubscribCell ()
/**
 *  cell底部的view
 */
@property (weak, nonatomic) IBOutlet UIView *underView;
/**
 *  标题label
 */
@property (weak, nonatomic) IBOutlet UILabel *titleLb;
@property (weak, nonatomic) IBOutlet UILabel *comeFromLb;
@property (weak, nonatomic) IBOutlet UILabel *timeLb;
@property (weak, nonatomic) IBOutlet UILabel *authLb;
@property (weak, nonatomic) IBOutlet UIButton *collectBtn;
/**
 *  批示btn
 */
@property (weak, nonatomic) IBOutlet UIButton *reportBtn;
/**
 *  正反面属性btn
 */
@property (weak, nonatomic) IBOutlet UIButton *featureBtn;

/**  评论Btn */
@property (weak, nonatomic) IBOutlet UIButton *commentBtn;

/**  收藏夹列表 */
@property (nonatomic, strong) NSArray *collects;

/**  相似btn */
@property (weak, nonatomic) IBOutlet UIButton *similarBtn;

/**  删除btn */
@property (weak, nonatomic) IBOutlet UIButton *deleteBtn;
@end
@implementation KDSubscribCell
+ (instancetype)cellWithTableView:(UITableView *)tableView{
    static NSString *cellId =@"KDSubscribCell";
    
    
    KDSubscribCell *cell =[tableView dequeueReusableCellWithIdentifier:cellId];
    cell.backgroundColor = BackGroundColor;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.similarBtn.layer.cornerRadius = 3.0f;
    cell.similarBtn.clipsToBounds = YES;
    cell.similarBtn.layer.borderWidth = 0.5;
//    [cell.reportBtn setImage:[UIImage imageNamed:@"已上报"] forState:UIControlStateDisabled];
    //监听收藏状态改变之后的通知
    [[NSNotificationCenter defaultCenter] addObserver:cell selector:@selector(SingleWebViewControllerCollectionBtnClick:) name:@"SingleWebViewControllerCollectionBtnClickToSubscribNoty" object:nil];
    
    
    return cell;
}
- (void)awakeFromNib {
    // Initialization code
}
- (void)setModel:(KDSubscribCellModel *)model{
    _model = model;
    self.collectBtn.selected = model.isCollection;
    
    self.titleLb.attributedText = [NSString praseHtmlStr:model.craw_title ];
    self.comeFromLb.text = model.site_name;
    self.timeLb.text = model.craw_publishtime;
    self.authLb.text = model.craw_author;
    self.featureBtn.selected = (model.analy_posneg == -1)?YES:NO;
    self.similarBtn.selected = !model.similarNumber;
    if (model.similarNumber) {
        self.similarBtn.layer.borderColor = WQColor(255, 149, 0).CGColor;
        self.similarBtn.backgroundColor = WQColor(255, 149, 0);
    }else{
        self.similarBtn.layer.borderColor = WQColor(221, 221, 221).CGColor;
        self.similarBtn.backgroundColor = [UIColor whiteColor];
    }
    [self.similarBtn setTitle:[NSString stringWithFormat:@"相关%ld",model.similarNumber] forState:UIControlStateNormal];
    
//    self.indexCover_Cons_w.constant = 20 *(3 - model.msg_yjzs);
//    if (model.read) {
//        self.titleLb.textColor = WQColor(178, 182, 184);
//    }else{
//        self.titleLb.textColor = [UIColor blackColor];
//    }
    
//    self.collectBtn.selected = model.isSave;
//    self.reportBtn.selected = model.report;
    
}

#pragma mark － 事件点击区
/**  收藏按钮被点击了 */
- (IBAction)collectBtnClick:(UIButton *)sender {
    
    //2.选择收藏夹
    if (_delegate && [_delegate respondsToSelector:@selector(subscribCell:collectBtnClick:)]) {
                        [_delegate subscribCell:self collectBtnClick:self.collectBtn];
        
    }
    
}
/**  批示按钮被点击了 */
- (IBAction)reportBtnClick:(UIButton *)sender {
    if (_delegate && [_delegate respondsToSelector:@selector(subscribCell:reportBtnClick:)]) {
        [_delegate subscribCell:self reportBtnClick:sender];
    }
}

/**
 *  删除按钮被点击了
 */
- (IBAction)deleteBtnClick:(UIButton *)sender {
    if (_delegate && [_delegate respondsToSelector:@selector(subscribCell:deleteBtnClick:)]) {
        [_delegate subscribCell:self deleteBtnClick:sender];
    }
}


- (void)dealloc{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}
#pragma mark - 通知接收区
- (void)SingleWebViewControllerCollectionBtnClick:(NSNotification *)noty{
//    NSString *docid = noty.userInfo[@"docid"];
//    if ([docid isEqualToString: self.model.docId]) {
//        self.model.save = [noty.userInfo[@"isCollect"] boolValue];
//        self.collectBtn.selected = self.model.isSave;
//    }
}
@end
